<template>
  <div class="audit">
    <div class="audit_title">是否审核通过？</div>
    <el-radio-group v-model="examine.resultFlag">
      <!-- <el-radio class="setPay_payment" label="0">微信商户号支付</el-radio> -->
      <el-radio  label="2">通过</el-radio>
      <el-radio  label="3">不通过</el-radio>
    </el-radio-group>
    <div v-if="examine.resultFlag === '3'">
      <el-form label-width="40px"  class="audit_textarea" >
        <el-form-item label="原因">
          <el-input placeholder="请输入原因"  maxlength="200" show-word-limit  type="textarea" v-model="examine.reason"></el-input>
        </el-form-item>
      </el-form>
    </div>
     <div v-if="dialogType=='shenheList'&&examine.resultFlag === '2'">
      <el-form label-width="40px"  class="audit_textarea" >
        <el-form-item label="备注">
          <el-input placeholder="请输入备注"  maxlength="200" show-word-limit  type="textarea" v-model="examine.remake"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AuditOperation',
  props: {
    isBatch: { // 判断是否多选
      type: Boolean,
      default: false
    },
    afterNos: { // 售后编号
      type: Array,
      default: []
    },
    dialogType: { // 状态
      type: String,
      default: []
    },
    orderObj: {
      type: Object,
      default: {}
    },
    shenheId: {

    },
    isCleanUp: { // 是否清空
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      examine: { // 是否通过审核
        resultFlag: '2', // 审批结果(2通过；3驳回)
        reason: '',
        remake: ''
      }
    }
  },
  computed: {},
  watch: {
    orderObj: {
      deep: true,
      handler (newVal, oldVal) {
        if (this.isCleanUp) {
          this.examine.reason = ''
          this.examine.remake = ''
          this.examine.resultFlag = '2'
        }
      }
    }
  },
  created () {},
  mounted () {
    this.$nextTick(() => {})
  },
  methods: {
    open () {
      this.visible = true
    },
    close () {
      this.visible = false
    },
    closed () {
      this.$emit('closed')
    },
    // 订单审核批量审核/审核
    auditSubmitList () {
      const isBatch = this.isBatch
      if (!isBatch && this.afterNos.length > 1) {
        return this.$message.warning('当前不是多选审核！')
      }
      if (this.examine.resultFlag == 2) {
        const orderObj = this.orderObj
        const ids = this.afterNos
        const params = {}
        console.log(ids, orderObj, 'orderObjorderObjorderObjorderObj')
        params.ids = []
        params.reason = this.examine.remake
        params.resultFlag = this.examine.resultFlag

        if (ids.length === 0) {
          console.log('length')
          params.ids.push(orderObj.orderNo)
        } else {
          const arr = []
          ids.forEach(item => {
            arr.push(item.orderNo)
          })
          params.ids = arr
        }
        this.$api.doPass(params).then((res) => {
          if (res.code === 0) {
            this.$emit('submitState', true)
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.examine.reason = ''
            this.examine.resultFlag = ''
            this.examine.remake = ''
            // this.fetchData('search')
          } else {
            this.$emit('submitState', false)
          }
        }).catch((err) => {
          this.$emit('submitState', false)
          console.log(err)
        })
      } else {
        if (this.examine.reason == '') {
          this.$message.warning('请填写不通过原因！')
          return
        }
        console.log('进来')
        const orderObj = this.orderObj
        const ids = this.afterNos
        const params = Object.assign({}, this.examine)
        console.log(ids, orderObj, 'orderObjorderObjorderObjorderObj')
        params.ids = []
        params.reason = this.examine.reason
        if (ids.length === 0) {
          console.log('length')
          params.ids.push(orderObj.orderNo)
        } else {
          const arr = []
          ids.forEach(item => {
            arr.push(item.orderNo)
          })
          params.ids = arr
        }
        this.$api.doReject(params).then((res) => {
          if (res.code == 0) {
            this.$emit('submitState', true)
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
          } else {
            this.$emit('submitState', false)
          }
          // this.fetchData('search')
          this.examine.reason = ''
          this.examine.resultFlag = ''
        }).catch((err) => {
          this.$emit('submitState', true)
          console.log(err)
        })
      }
    },
    submitList () {
      console.log('进来')
      const orderObj = this.orderObj
      const ids = this.afterNos
      const params = Object.assign({}, this.examine)
      console.log(ids, orderObj, 'orderObjorderObjorderObjorderObj')
      params.ids = []
      if (ids.length === 0) {
        console.log('length')
        params.ids.push(orderObj.orderNo)
      } else {
        const arr = []
        ids.forEach(item => {
          arr.push(item.orderNo)
        })
        params.ids = arr
      }
      this.$api.doPass(params).then((res) => {
        if (res.code === 0) {
          this.$emit('submitState', true)
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
        } else {
          this.$emit('submitState', false)
        }
      }).catch((err) => {
        this.$emit('submitState', false)
        console.log(err)
      })
    },
    // 订单批量审核/审核
    submit () {
      const orderObj = this.orderObj
      const afterNos = this.afterNos
      const params = Object.assign({}, this.examine)
      params.afterNos = []
      if (JSON.stringify(orderObj) !== '{}') {
        params.afterNos.push(orderObj.afterNo)
      } else {
        const arr = []
        afterNos.forEach(item => {
          arr.push(item.afterNo)
        })
        params.afterNos = arr
      }
      this.$api.afterDoApprove(params).then((res) => {
        if (res.code === 0) {
          this.$emit('submitState', true)
        } else {
          this.$emit('submitState', false)
        }
      }).catch((err) => {
        this.$emit('submitState', false)
        console.log(err)
      })
    },
    // 售后审核/批量审核
    afterSalesubmit () {
      if (this.examine.resultFlag == 3 && this.examine.reason == '') {
        return this.$message.warning('请填写不通过原因！')
      }
      const orderObj = this.orderObj
      const afterNos = this.afterNos
      console.log(this.afterNos, 'this.afterNos')
      const params = Object.assign({}, this.examine)
      params.afterNos = []
      if (afterNos.length === 0) {
        console.log('length')
        params.afterNos.push(orderObj.afterNo)
      } else {
        const arr = []
        afterNos.forEach(item => {
          arr.push(item.afterNo)
        })
        params.afterNos = arr
      }
      // if (JSON.stringify(orderObj) !== '{}') {
      //   params.afterNos.push(orderObj.afterNo)
      // } else {
      //   const arr = []
      //   afterNos.forEach(item => {
      //     arr.push(item.afterNo)
      //   })
      //   params.afterNos = arr
      // }
      this.$api.afterSaleDoApprove(params).then((res) => {
        this.$emit('submitState', true)
      }).catch((err) => {
        this.$emit('submitState', true)
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.audit_title{
  font-weight: bold;
  margin-bottom: 20px;font-size: 16px;
}
.audit_textarea{
  margin-top: 10px;
  /deep/.el-textarea__inner{
    margin-top: 13px;
    height: 132px;
  }
}
</style>
